/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

import Model.Bo.CategoryBO;
import Model.Bo.CustomerBO;
import Model.Entity.CategoryEntity;
import Model.Entity.CustomerEntity;
import java.io.IOException;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.List;
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author trung
 */
@WebFilter(filterName = "logFilter", urlPatterns = {"/login.jsp"}, dispatcherTypes = {DispatcherType.FORWARD, DispatcherType.REQUEST})
public class loginFilter implements Filter {

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException {

        HttpServletRequest httpServletRequest = (HttpServletRequest) request;
        HttpServletResponse httpServletResponse = (HttpServletResponse) response;
        CustomerBO cus = new CustomerBO();
        List<CustomerEntity> cusList = cus.getAll();
        Object o = httpServletRequest.getAttribute("load");
        CategoryBO category = new CategoryBO();
        List<CategoryEntity> cateList = category.getAll();
        request.setAttribute("category", cateList);

        if (request.getAttribute("fixText").equals("Cá Nhân")) {
            httpServletResponse.sendRedirect("/TrangChu.jsp");
        } else {
            chain.doFilter(request, response);
        }
    }

    @Override
    public void destroy() {
    }
}
